package erfgame.core.graphics.renderer.animation;

import java.util.Map;

import erfgame.core.entity.EntityType;
import erfgame.core.entity.State;

public class DelegatingByStateStateAnimationCycleFactory implements
        StateAnimationCycleFactory {
    
    private Map<State, StateAnimationCycleFactory> children;
    private StateAnimationCycleFactory defaultAnimationCycleFactory;
    
    public DelegatingByStateStateAnimationCycleFactory( Map<State, StateAnimationCycleFactory> children, StateAnimationCycleFactory defaultAnimationCycleFactory ) {
        this.children = children;
        this.defaultAnimationCycleFactory = defaultAnimationCycleFactory;
    }
    
    public AnimationCycle getAnimationCycle(State state, EntityType entityType) {
        StateAnimationCycleFactory child = this.children.get(state);
        if( child == null ) {
            child = defaultAnimationCycleFactory;
        }
        return child.getAnimationCycle(state, entityType);
    }

}
